import sched
import time
import subprocess

scheduler = sched.scheduler(time.time, time.sleep)

def run_script(script_path):
    try:
        subprocess.run(['python', script_path], check=True)
        print(f"{script_path}成功执行.")
    except subprocess.CalledProcessError as e:
        print(f"运行出错{script_path}: {e}")

def schedule_script(script_path, interval):
    scheduler.enter(interval, 1, schedule_script, (script_path, interval))
    run_script(script_path)

def start_scheduler(script_path, interval):
    schedule_script(script_path, interval)
    scheduler.run()

if __name__ == "__main__":
    script_path = 'spid_twitter.py'  #文件路径和名称
    interval = 1000  # 时间间隔（秒）
    start_scheduler(script_path, interval)
